import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int size = scan.nextInt() ;
        int p = scan.nextInt() ;
        int[] array = new int[size];
        int max = -1 ;
        for (int i = 0 ; i < size ; i ++) {
            array[i] = scan.nextInt();
            if(array[i] > max){
                max = array[i];
            }
        }
        int sum = 0 ; 
        for(int i = 0 ; i <= size ; i ++){
            int tmp = 0 ; 
            for(int j = 0; j <size ; j ++){
                if(Math.abs(array[j]-i) <= p){
                    tmp ++ ;
                }
            }
            if(sum < tmp){
                sum = tmp ;
            }
        }
        System.out.println(sum);

    }
}